#coding:utf-8
from itertools import chain
from dateutil.relativedelta import relativedelta
import requests
import common.config
from common.config import *
from common.mysql_db_data import MysqlDbTriton


class AttributeManage:
    def getProductAttributeList(self,env):
        base_url = getconf(env, "data_url1")
        url = base_url + "easydata-web/v1/event/getProductAttributeList"
        token = cmslogin(env)
        header={"Content-Type": "application/json;charset=UTF-8","token":token}
        data={'current': '1','size': '50'}
        r=requests.get(url=url,params=data,headers=header)
        print('属性清单')
        return r.json()

    def getAttributeDetail(self,env):
        base_url = getconf(env, "data_url1")
        url = base_url + "easydata-web/v1/event/getAttributeDetail/37"
        token = cmslogin(env)
        header={"Content-Type": "application/json;charset=UTF-8","token":token}
        r=requests.get(url,headers=header)
        print('属性详情')
        return r.json()

    def getAppNames(self,env):
        base_url = getconf(env, "data_url1")
        url = base_url + "easydata-web/v1/event/getAppNames"
        token = cmslogin(env)
        header={"Content-Type": "application/json;charset=UTF-8","token":token}
        r=requests.get(url,headers=header)
        print('属性名称')
        return r.json()

    def createAttribute(self,env):
        base_url = getconf(env, "data_url1")
        url = base_url + "easydata-web/v1/event/createAttribute"
        token = cmslogin(env)
        header={"Content-Type": "application/json;charset=UTF-8","token":token}
        r=requests.post(url,headers=header)
        print('点击新建产品属性清单')
        return r.json()

    def saveAttribute(self,env):
        base_url = getconf(env, "data_url1")
        url = base_url + "easydata-web/v1/event/saveAttribute"
        token = cmslogin(env)
        data={"id":None,"productName":"autotest","appName":"com.autotest","appId":"自动化测试","appVersion":"3.2.1.1","productFieldList":[{"baseFieldId":1,"defaultValue":"","fieldFlag":1,"reportDesc":"由上报端生成唯一"},{"baseFieldId":2,"defaultValue":"","fieldFlag":1,"reportDesc":"业务上报时约定"},{"baseFieldId":3,"defaultValue":"","fieldFlag":1,"reportDesc":"日志生成时时间戳(精确到毫秒)"},{"baseFieldId":4,"defaultValue":"","fieldFlag":1,"reportDesc":"对接时数据平台给到"},{"baseFieldId":5,"defaultValue":"","fieldFlag":1,"reportDesc":"业务方定义"},{"baseFieldId":6,"defaultValue":"","fieldFlag":1,"reportDesc":"上一级页面"},{"baseFieldId":7,"defaultValue":"","fieldFlag":1,"reportDesc":"页面code（业务名称）"},{"baseFieldId":8,"defaultValue":"","fieldFlag":1,"reportDesc":"元素code（功能名称）"},{"baseFieldId":9,"defaultValue":"","fieldFlag":1,"reportDesc":"枚举"},{"baseFieldId":10,"defaultValue":"","fieldFlag":0,"reportDesc":"同一渠道上报名称或者ID需要统一"},{"baseFieldId":11,"defaultValue":"","fieldFlag":0,"reportDesc":"同一渠道上报名称或者ID需要统一"},{"baseFieldId":12,"defaultValue":"","fieldFlag":0,"reportDesc":"同一渠道上报名称或者ID需要统一"},{"baseFieldId":13,"defaultValue":"","fieldFlag":0,"reportDesc":"同一渠道上报名称或者ID需要统一"},{"baseFieldId":14,"defaultValue":"","fieldFlag":0,"reportDesc":"同一渠道上报名称或者ID需要统一"},{"baseFieldId":15,"defaultValue":"","fieldFlag":0,"reportDesc":"同一渠道上报名称或者ID需要统一"},{"baseFieldId":16,"defaultValue":"","fieldFlag":0,"reportDesc":""},{"baseFieldId":17,"defaultValue":"","fieldFlag":0,"reportDesc":""},{"baseFieldId":18,"defaultValue":"","fieldFlag":1,"reportDesc":"json对象根据业务需求选择以下产品属性字段"},{"baseFieldId":19,"defaultValue":"","fieldFlag":0,"reportDesc":"需要分析应用模板使用情况时上报"},{"baseFieldId":20,"defaultValue":"","fieldFlag":0,"reportDesc":"页面URL地址"},{"baseFieldId":21,"defaultValue":"","fieldFlag":1,"reportDesc":"当前事件相关属性信息(具体业务具体定义json串){\"gameId\":\"001\"}"},{"baseFieldId":24,"defaultValue":"","fieldFlag":0,"reportDesc":"终端设备唯一ID 如(uuid,IMEI,IDFA等)"},{"baseFieldId":23,"defaultValue":"","fieldFlag":0,"reportDesc":"手机号"},{"baseFieldId":22,"defaultValue":"","fieldFlag":0,"reportDesc":"用户唯一Id"},{"baseFieldId":25,"defaultValue":"","fieldFlag":0,"reportDesc":"例:活动Id"},{"baseFieldId":26,"defaultValue":"","fieldFlag":0,"reportDesc":"例:wechat"},{"baseFieldId":27,"defaultValue":"","fieldFlag":0,"reportDesc":"openId"},{"baseFieldId":28,"defaultValue":"","fieldFlag":0,"reportDesc":"开放平台Id"},{"baseFieldId":29,"defaultValue":"","fieldFlag":0,"reportDesc":"公众号Id"},{"baseFieldId":30,"defaultValue":"","fieldFlag":1,"reportDesc":"终端设备mac(小写格式如5c:e0:c5:0e:68:67)"},{"baseFieldId":31,"defaultValue":"","fieldFlag":0,"reportDesc":"人脸ID"},{"baseFieldId":32,"defaultValue":"","fieldFlag":0,"reportDesc":"组件ID(如建站组件)"},{"baseFieldId":33,"defaultValue":"","fieldFlag":0,"reportDesc":"浏览器信息json串"},{"baseFieldId":34,"defaultValue":"","fieldFlag":0,"reportDesc":"终端设备相关信息json串定义设备属性字段"}],"status":0}
        header={"Content-Type": "application/json;charset=UTF-8","token":token}
        r=requests.post(url,data=json.dumps(data),headers=header)
        print('暂存',r.json())
        return r.json()

    def delAttribute(self,env):
        base_url = getconf(env, "data_url1")
        url = base_url + "easydata-web/v1/event/delAttribute?"
        token = cmslogin(env)
        #data={"id":None,"productName":"autotest","appName":"com.autotest","appId":"自动化测试","appVersion":"3.2.1.1","productFieldList":[{"baseFieldId":1,"defaultValue":"","fieldFlag":1,"reportDesc":"由上报端生成唯一"},{"baseFieldId":2,"defaultValue":"","fieldFlag":1,"reportDesc":"业务上报时约定"},{"baseFieldId":3,"defaultValue":"","fieldFlag":1,"reportDesc":"日志生成时时间戳(精确到毫秒)"},{"baseFieldId":4,"defaultValue":"","fieldFlag":1,"reportDesc":"对接时数据平台给到"},{"baseFieldId":5,"defaultValue":"","fieldFlag":1,"reportDesc":"业务方定义"},{"baseFieldId":6,"defaultValue":"","fieldFlag":1,"reportDesc":"上一级页面"},{"baseFieldId":7,"defaultValue":"","fieldFlag":1,"reportDesc":"页面code（业务名称）"},{"baseFieldId":8,"defaultValue":"","fieldFlag":1,"reportDesc":"元素code（功能名称）"},{"baseFieldId":9,"defaultValue":"","fieldFlag":1,"reportDesc":"枚举"},{"baseFieldId":10,"defaultValue":"","fieldFlag":0,"reportDesc":"同一渠道上报名称或者ID需要统一"},{"baseFieldId":11,"defaultValue":"","fieldFlag":0,"reportDesc":"同一渠道上报名称或者ID需要统一"},{"baseFieldId":12,"defaultValue":"","fieldFlag":0,"reportDesc":"同一渠道上报名称或者ID需要统一"},{"baseFieldId":13,"defaultValue":"","fieldFlag":0,"reportDesc":"同一渠道上报名称或者ID需要统一"},{"baseFieldId":14,"defaultValue":"","fieldFlag":0,"reportDesc":"同一渠道上报名称或者ID需要统一"},{"baseFieldId":15,"defaultValue":"","fieldFlag":0,"reportDesc":"同一渠道上报名称或者ID需要统一"},{"baseFieldId":16,"defaultValue":"","fieldFlag":0,"reportDesc":""},{"baseFieldId":17,"defaultValue":"","fieldFlag":0,"reportDesc":""},{"baseFieldId":18,"defaultValue":"","fieldFlag":1,"reportDesc":"json对象根据业务需求选择以下产品属性字段"},{"baseFieldId":19,"defaultValue":"","fieldFlag":0,"reportDesc":"需要分析应用模板使用情况时上报"},{"baseFieldId":20,"defaultValue":"","fieldFlag":0,"reportDesc":"页面URL地址"},{"baseFieldId":21,"defaultValue":"","fieldFlag":1,"reportDesc":"当前事件相关属性信息(具体业务具体定义json串){\"gameId\":\"001\"}"},{"baseFieldId":24,"defaultValue":"","fieldFlag":0,"reportDesc":"终端设备唯一ID 如(uuid,IMEI,IDFA等)"},{"baseFieldId":23,"defaultValue":"","fieldFlag":0,"reportDesc":"手机号"},{"baseFieldId":22,"defaultValue":"","fieldFlag":0,"reportDesc":"用户唯一Id"},{"baseFieldId":25,"defaultValue":"","fieldFlag":0,"reportDesc":"例:活动Id"},{"baseFieldId":26,"defaultValue":"","fieldFlag":0,"reportDesc":"例:wechat"},{"baseFieldId":27,"defaultValue":"","fieldFlag":0,"reportDesc":"openId"},{"baseFieldId":28,"defaultValue":"","fieldFlag":0,"reportDesc":"开放平台Id"},{"baseFieldId":29,"defaultValue":"","fieldFlag":0,"reportDesc":"公众号Id"},{"baseFieldId":30,"defaultValue":"","fieldFlag":1,"reportDesc":"终端设备mac(小写格式如5c:e0:c5:0e:68:67)"},{"baseFieldId":31,"defaultValue":"","fieldFlag":0,"reportDesc":"人脸ID"},{"baseFieldId":32,"defaultValue":"","fieldFlag":0,"reportDesc":"组件ID(如建站组件)"},{"baseFieldId":33,"defaultValue":"","fieldFlag":0,"reportDesc":"浏览器信息json串"},{"baseFieldId":34,"defaultValue":"","fieldFlag":0,"reportDesc":"终端设备相关信息json串定义设备属性字段"}],"status":0}
        data = {"id": 60}
        header={"Content-Type": "application/json;charset=UTF-8","token":token}
        r=requests.delete(url,params=data,headers=header)
        print('删除',r.json())
        return r.json()






#a=AttributeManage()
#a.saveAttribute('test')
